RealBasic CGI Shell
RealBasic CGI Shell is a free RealBasic component that RealBasic programmers can use to quickly create custom CGIs.
Requirements
RealBasic CGI requires that you have the RealBasic programming application available from RealSoftware.
Quick Start
A sample cgi can be created by making a new RealBasic application and dragging the App component and the Example component into the project window. Build your new application naming it Test.cgi. Put it in your web server folder on the same level as the sample test_form.html document. View the test_form.html document with your web browser. If you are testing locally, type in your domain name so the page is served using the web server and not simply opened off the hard drive. Fill out the form and submit it to test your new cgi. Once you have your Test.cgi working, view the code in the example component and edit it to suit your needs. Do not rename any of the components, including the ProcessData method.
Using Data from the Web
To learn more about the type of data coming from the web, please see the example parameters at http://www.biap.com/DataPig/mrwheat/cgiParams.html courtesy of BiapSystems, Inc. These parameters are for the WebStar webserver, but are common to most Macintosh webservers.
Post Args
To obtain data submitted from a web form using the post method, you can use the app.field("field_name") call or the app.num(x) call. To use the app.field("field_name") call, replace field_name with the name of the field you would like to obtain. Make sure it's in quotes. To use the app.num(x) call, replace the x with the number of the field you would like to obtain. The number should not be in quotes. Please keep in mind that not all browsers return data in the same order; therefore, the app.num(x) call is not a reliable call to use if you're looking for a specific field. The app.num(x) call is ideal to use in a loop where you would like all fields to be processed the same. To obtain the name of the corresponding label or field name, using app.label(x). You can determine how many post args were submitted using the app.count() function. Keep in mind that the submit button will also be included as a field.
Search Args
If you are using the get method on your form, or you would like to get search args out of an url directed to the cgi, you can use the app.field("field_name") method described above to obtain the specific search arg. You can not use app.num with search args. Since app.field is available for both search args and post args, if you have search args and post args with the same name, the value of the search arg will be returned and the post arg will be ignored.
Web data as properties
All incoming web data is preserved in the shell within properties. If you would like to manage your post args and search args as double arrays, you can refer to them as the properties app.form_args(0, 1) and app.search_args(0, 1) respectively. Other properties you can refer to in order to obtain the corresponding values are:
- app.action - The action used in the web form.
- app.action_path - The path to the cgi if it's being executed as an action.
- app.client - The domain name of the browser, or IP address if the domain can't be resolved.
- app.client_ip - IP address of the browser.
- app.full - The full http request received from the browser.
- app.ID - A unique long integer value to identify the browser. This value can be used to track the browser during a session on your site.
- app.method - The method, post or get, used in the submitted form.
- app.pass - The password the browser is logged in under (if applicable).
- app.path - The path to the cgi being triggered by the web form.
Note: The difference between app.path and app.action_path is that app.path contains the file path portion of the URL when the cgi is being executed as an action while the app.action_path contains the actual path to the cgi.
- app.path_args - The path args are data following a dollar sign in the URL.
- app.port - The port at which the web server is serving.
- app.refer - The page from which the cgi call was sent.
- app.server - Domain name or IP of the web server from which the cgi call came.
- app.type - MIME type of post arguments, if present.
- app.user - Username the browser is logged in under (if applicable).
Returning Results
Whatever the ProcessData method returns will be sent back to the browser. The cgi shell can handle strings, graphics, or another URL to instantly send the user to. Strings are the default. If you wish to return binary data equivalent to a jpeg or gif graphic, you need to set the app.header property to
"graphic".
app.header="graphic"
If you wish to return an URL for a redirect statement, set the app.header to "redirect" and set the app.redirect property to the complete URL of the new location.
app.header="redirect"
app.redirect="http://www.vivaladata.com"
Disclaimer
This program is free. Use at your own risk. Support and modifications are available for a fee. Distribution is prohibited without written consent of author. All rights reserved.
About the Author
RealBasic CGI Shell was written by Diana Cassady of VivaLaData. Program last edited 9/28/98. Suggestions and comments welcome. Thanks for your interest in my work.